package com.jz.community.modulemine.net;

import android.app.Activity;

import com.alibaba.fastjson.JSON;
import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.modulemine.integral.bean.IntegralInfo;

import java.util.HashMap;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Tony.Fan on 2018/6/14 17:47
 */
public class DeleteJpushTask extends RxTask<String, Integer, BaseResponseInfo> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public DeleteJpushTask(Activity activity,
                           ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected BaseResponseInfo doInBackground(String... params) {
        // 执行请求
        String result = OkHttpUtil.delete(Constant.DELETE_PUSHID_URL, getParam());
        BaseResponseInfo info = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            info = JSON.parseObject(result, BaseResponseInfo.class);
        }
        return info;
    }

    @Override
    protected void onPostExecute(BaseResponseInfo result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    /**
     * 获取请求所需的参数
     *
     * @param
     * @return
     */
    private HashMap<String, Object> getParam() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("jpushid", JPushInterface.getRegistrationID(activity));
        hashMap.put("usertype", "member");
        return hashMap;
    }
}